#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: 闲欢
"""
import numpy as np

a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("初始数组：")
print(a)
print('\n')


print(np.char.center('最小值', 15, '*'))
print("所有维度的最小值：")
print(np.amin(a))
print('\n')
print("0轴的最小值：")
print(np.amin(a, 0))
print('\n')
print("1轴的最小值：")
print(np.amin(a, 1))
print('\n')


print(np.char.center('最大值', 15, '*'))
print("所有维度的最大值：")
print(np.amax(a))
print('\n')
print("0轴的最大值：")
print(np.amax(a, 0))
print('\n')
print("1轴的最大值：")
print(np.amax(a, 1))
print('\n')


print(np.char.center('求和', 15, '*'))
print("所有维度的和：")
print(np.sum(a))
print('\n')
print("按0轴求和：")
print(np.sum(a, 0))
print('\n')
print("按1轴求和：")
print(np.sum(a, 1))
print('\n')

print(np.char.center('最大值与最小值的差', 15, '*'))
print("所有维度的极差：")
print(np.ptp(a))
print('\n')
print("0轴的极差：")
print(np.ptp(a, 0))
print('\n')
print("1轴的极差：")
print(np.ptp(a, 1))
print('\n')

print(np.char.center('百分位数', 15, '*'))
print("50%的分位数，即数组排序之后的中位数：")
print(np.percentile(a, 50))
print('\n')
print("0轴的中位数：")
print(np.percentile(a, 50, 0))
print('\n')
print("1轴的中位数：")
print(np.percentile(a, 50, 1))
print('\n')

print(np.char.center('计算中位数', 15, '*'))
print("所有元素的中位数：")
print(np.median(a))
print('\n')
print("0轴的中位数：")
print(np.median(a, 0))
print('\n')
print("1轴的中位数：")
print(np.median(a, 1))
print('\n')

print(np.char.center('计算算术平均值', 15, '*'))
print("所有元素的算术平均值：")
print(np.mean(a))
print('\n')
print("0轴的算术平均值：")
print(np.mean(a, 0))
print('\n')
print("1轴的算术平均值：")
print(np.mean(a, 1))
print('\n')

print(np.char.center('加权平均值', 15, '*'))
b = np.array([1, 2, 3, 4])
print("所有元素的加权平均值（不指定权重相当于求平均值）：")
print(np.average(b))
print('\n')
print("指定权重的加权平均值：")
print(np.average(b, weights=[4, 3, 2, 1]))
print('\n')
print("指定权重的加权平均值以及权重的和：")
print(np.average(b, weights=[4, 3, 2, 1], returned=True))
print('\n')

print(np.char.center('计算方差', 15, '*'))
print(np.var([1, 2, 3, 4]))
print('\n')

print(np.char.center('计算标准差', 15, '*'))
print(np.std([1, 2, 3, 4]))
print('\n')
